package org.kl.auditsupervision.service.fnd;

 

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.kl.auditsupervision.entity.fnd.SjFx;
import org.kl.auditsupervision.repository.fnd.SjFxDao;
import org.kl.bf.service.BasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import org.springside.modules.utils.Collections3;

import com.alibaba.fastjson.JSON;
 
@Component
// 默认将类中的所有public函数纳入事务管理.
@Transactional
public class SjFxService extends BasicService<SjFx> {
	@Autowired
	private SjFxDao sjFxDao;
	
	public List<SjFx> findBySjjcPjId(String sjjcPjId){
		return sjFxDao.findBySjjcPjId(sjjcPjId);
	}
	
	public void save(SjFx entity, @RequestParam(value = "inserted") String detailInserted,
			@RequestParam(value = "updated") String detailUpdated, @RequestParam(value = "deleted") String detailDeleted) {
		sjFxDao.save(entity);
		if (StringUtils.isNotBlank(detailInserted)) {
			List<SjFx> inserts = JSON.parseArray(detailInserted, SjFx.class);
			if (Collections3.isNotEmpty(inserts)) {
				for (SjFx a : inserts) {
					// 增加与主表相关的数据复制代码
					sjFxDao.save(a);
				}
			}
		}
		if (StringUtils.isNotBlank(detailUpdated)) {
			List<SjFx> updates = JSON.parseArray(detailUpdated, SjFx.class);
			if (Collections3.isNotEmpty(updates)) {
				for (SjFx b : updates) {
					sjFxDao.save(b);
				}
			}
		}
		if (StringUtils.isNotBlank(detailDeleted)) {
			List<SjFx> deletes = JSON.parseArray(detailDeleted, SjFx.class);
			if (Collections3.isNotEmpty(deletes)) {
				sjFxDao.delete(deletes);
			}
		}
	}
}
